package com.xdf.docmanagementsystem.service.impl;

import com.xdf.docmanagementsystem.service.ViewFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @program: doc-management-system
 * @description: 读取Text文件
 * @author: Zhang
 * @create: 2020-06-30 16:12
 **/
public class ViewTextFileImpl implements ViewFile {
    @Override
    public synchronized void view(OutputStream os, File file) throws IOException {
        // 输出text文件
        FileInputStream fis = new FileInputStream(file);
        byte[] b = new byte[1024];
        while (fis.read(b) != -1) {
            os.write(b);
            os.flush();
        }
        if (fis != null) {
            fis.close();
        }
        if (os != null) {
            os.close();
        }
    }
}
